package com.cefa.edu.common;

import org.apache.commons.lang3.StringUtils;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.time.LocalDate;


/**
 * Created by qimwang on 8/3/17.
 */
@Configuration
public class DateVerifyInterceptor implements HandlerInterceptor {

    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object var3) throws Exception {
        boolean ret = true;
        String from = request.getParameter("from");
        String to = request.getParameter("to");
        try {
            if (StringUtils.isNotEmpty(from)) {
                LocalDate.parse(from.trim());
            }

            if (StringUtils.isNotEmpty(to)) {
                LocalDate.parse(to.trim());
            }
        } catch (Exception e) {
            ret = false;
        }
        return ret;
    }

    public void postHandle(HttpServletRequest var1, HttpServletResponse var2, Object var3, ModelAndView var4) throws Exception {

    }

    public void afterCompletion(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object var3, Exception var4) throws Exception {

    }
}
